<script setup>
import { ref, onMounted } from 'vue';
import request from "../utils/request";

// 定义响应式数据
const isCollapse = ref(false);
const asideWidth = ref('200px');
const collapseIcon = ref('el-icon-s-fold');
const users = ref([]);

// 组件挂载时获取数据
onMounted(async () => {
  try {
    const response = await request.get('/selectAll');
    users.value = response.data; // 假设 response.data 已经是用户列表
  } catch (error) {
    console.error('Failed to fetch users:', error);
  }
});

// 定义方法
function handleCollapse() {
  isCollapse.value = !isCollapse.value;
  asideWidth.value = isCollapse.value ? '64px' : '200px';
  collapseIcon.value = isCollapse.value ? 'el-icon-s-unfold' : 'el-icon-s-fold';
}
</script>

<template>
  <div>
    <el-container>
      <!--      侧边栏-->
      <el-aside :width="asideWidth" style="min-height: 200vh; background-color:#001529">
        <div style="  height: 60px ; color: #cccccc; display: flex;align-items: center;justify-content: center">
          <img src="../assets/img/b.png" alt="" style="width:40px;height: 40px">
          <span class="logo-title" v-show="!isCollapse">小张水果店</span>

        </div>

        <!--        菜单栏-->
        <el-menu :collapse="isCollapse" :collapse-transition="false" router  background-color="#001529" text-color="rgba(255, 255, 255, 0.65)" active-text-color="#fff" style="border: none">
          <el-menu-item index="/">
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-menu-item >
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-menu-item >
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-menu-item >
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>


          <el-submenu>
            <template slot="title">
              <i class="el-icon-menu"> </i>
              <span>信息管理</span>
            </template>
            <el-menu-item>用户信息</el-menu-item>
            <el-menu-item>管理员信息</el-menu-item>
            <el-menu-item index="/">
              <i class="el-icon-house"></i>
              <span slot="title">系统首页</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>

      </el-aside>

      <el-container>


        <!--        头部-->

        <el-header>
          <i :class="collapseIcon " style="font-size: 27px" @click="handleCollapse" ></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/user' }">用户管理</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex: 1;width: 0; display: flex;align-items: center;justify-content: flex-end">
            <el-dropdown placement="bottom">
              <div style="display: flex;align-items: center;cursor: default">
                <img src="../assets/img/b.png" alt="" style="width: 30px;height: 30px">
                <span>管理员</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click="">个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item @click="">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>


          </div>

        </el-header>


        <!--        主体-->
        <el-main>

          <!--            <div style="width: 50%;height: 200px; display: flex; box-shadow: 2px 0 6px rgba(0,21,42,.35)">-->
          <!--              你好吗-->

          <!--            </div>-->


          <div style="width: 70%;height: 400px; display: flex; box-shadow: 2px 0 6px rgba(0,21,42,.35)">

            <el-table :data="users">
              <el-table-column label="ID" prop="id"></el-table-column>
              <el-table-column label="用户名" prop="name"></el-table-column>
              <el-table-column label="年龄" prop="age"></el-table-column>
              <el-table-column label="性别" prop="gender"></el-table-column>
              <el-table-column label="电话" prop="phone"></el-table-column>
            </el-table>


          </div>


        </el-main>


      </el-container>


    </el-container>
  </div>
</template>


<style scoped>
.el-menu--inline {
  background-color: #000c17 !important;
}
.el-menu--inline .el-menu-item{
  background-color: #000c17 !important;
  padding-left: 67px !important;

}
.el-menu-item:hover, .el-submenu__title:hover{
  color: #fff !important;
}
.el-submenu__title:hover i {
  color: #fff;
}
.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 5px !important;
  width: calc(100% - 8px);
  margin: 4px !important;
}
.el-menu.is-active i, .el-menu-item.is-active .el-tooltip{
  margin-left: 0px;
}
.el-menu-item {
  margin: 4px !important;
  height: 40px !important;
  line-height: 40px !important;
}
.el-submenu__title {
  margin: 4px !important;
  height: 40px !important;
  line-height: 40px !important;
}
.el-submenu__title {
  min-height: 0 !important;
}
.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}
.el.aside {
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0,21,42,.35);
}
.logo-title {
  margin-left: 5px;
  font-size: 20px;
  transition: all .3s;
}
.el-header {
  box-shadow: 2px 0 6px rgba(0,21,42,.35);
  display: flex;
  align-items: center;
}




</style>
